package com.bt.framework.utils

import android.graphics.drawable.ColorDrawable
import androidx.annotation.ArrayRes
import androidx.annotation.ColorRes
import androidx.annotation.DimenRes
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toDrawable
import com.bt.framework.helper.SumAppHelper

/**
 *@author:hxm
 *@date: 2025/6/24 23:50
 *@version:
 *@description: 获取资源常用工具类
 */

/**
 * 获取字符串数组
 */
fun getStringArrayFromResource(@ArrayRes arrayId: Int): Array<String> {
    return SumAppHelper.getApplication().resources.getStringArray(arrayId)
}

/**
 * 获取字符串
 */
fun getStringFromResource(@StringRes strResId: Int): String {
    return SumAppHelper.getApplication().getString(strResId)
}

/**
 * 获取格式化字符串
 */
fun getStringFromFromResource(@StringRes strResId: Int, vararg formatArgs: Any?): String? {
    return SumAppHelper.getApplication().getString(strResId, *formatArgs)
}

/**
 * 获取颜色
 */
fun getColorFromResource(@ColorRes colorResId: Int): Int {
    return ContextCompat.getColor(SumAppHelper.getApplication(), colorResId)
}

/**
 * 获取小数
 */
fun getDecimalFromResource(@DimenRes dimenResId: Int): Int {
    return SumAppHelper.getApplication().resources.getDimensionPixelSize(dimenResId)
}

/**
 * 获取颜色
 */
fun getColorDrawable(@ColorRes colorResId: Int): ColorDrawable? {
    return ContextCompat.getColor(
        SumAppHelper.getApplication(),
        colorResId
    ).toDrawable()
}

